/**************************************************************************************************
 *  File Definition 
 *  - Delete data with AJAX
 -------------------------------------------------------------------  
 *  Run in PHP versions 4 and upper versions
 -------------------------------------------------------------------
 *  Apprain : Content Management Framework <http://www.apprain.com/>
 *  Download link: http://www.apprain.com/download
 *  Docs link: http://www.apprain.com/docs
 -------------------------------------------------------------------
 *  License text http://www.opensource.org/licenses/mit-license.php 
 *  About MIT license <http://en.wikipedia.org/wiki/MIT_License/>
**************************************************************************************************/

window.addEvent('domready', function() {

	var row_id;

	var req = new Request({url:base, 
		onSuccess: function(txt) {
			$(row_id).setStyle("display","none")			
		},
		onFailure: function() {
			alert("Sorry... Commond could not execute");
		}
	});
	
	
	$$('.link_delete').addEvent('click', function(e) {

		var model = this.title.split('_')[0];
		var id = this.title.split('_')[1];
		row_id = this.getParent("tr").get("id");

		var highlight = new Fx.Morph(row_id, {
		duration: 1500,
		link: 'cancel',
		transition: 'quad:out'
		});
		
		var orginal_color = $(row_id).getStyle('background-color');

		highlight.start({
				backgroundColor: ['#fff36f', '#FFFF1A' ],
				opacity: [.5, 1]
		});


		if(confirm("Are you sure to Delete?\n\nThere is currently a request to delete data from the sytem. You may can not undone.\n\nPress OK to continue, or Cancel to stay on same position."))
		{
			req.send({url:base + "/common/delete_row/" +  model + "/" + id });
		}	
		else
		{
			highlight.start({
				backgroundColor: ['#FFFF1A',orginal_color ],
				opacity: [.5, 1]
			});

		}
	});


	$$('.delete_informationset_file').addEvent('click', function (e) {

		var obj = this.getParent('span');
		this.src = base + '/images/loading.gif';
		this.setStyle('margin-left','5px');
		var req = new Request({url:base, 
			onSuccess: function(txt) {
				obj.setStyle('display','none');
			},
			onFailure: function() {
				alert("Sorry... Commond could not execute");
			}
		});

		req.send({url:base + "/common/delete_row/delete_informationset_file/" + this.id });
	});
});